/**
 * 
 */
package com.swim.natatoriuminfo.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.swim.natatoriuminfo.entity.ClickStats;
import com.swim.common.entity.CommonEcharts;
import com.swim.common.utils.DateUtil;
import com.swim.natatoriuminfo.dao.ClickStatsDao;

/**
 * 访问量统计Service
 * @author ljw
 * @version 2022-07-05
 */
@Service
@Transactional(readOnly=true)
public class ClickStatsService extends CrudService<ClickStatsDao, ClickStats> {
	
	/**
	 * 获取单条数据
	 * @param clickStats
	 * @return
	 */
	@Override
	public ClickStats get(ClickStats clickStats) {
		return super.get(clickStats);
	}
	
	/**
	 * 查询分页数据
	 * @param page 分页对象
	 * @param clickStats
	 * @return
	 */
	@Override
	public Page<ClickStats> findPage(Page<ClickStats> page, ClickStats clickStats) {
		return super.findPage(page, clickStats);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param clickStats
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(ClickStats clickStats) {
		super.save(clickStats);
	}
	
	/**
	 * 批量新增数据
	 * @param clickStatsList
	 */
	@Transactional(readOnly=false)
	public void insertBatch(List<ClickStats> clickStatsList) {
		dao.insertBatch(clickStatsList);
	}
	
	/**
	 * 更新状态
	 * @param clickStats
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(ClickStats clickStats) {
		super.updateStatus(clickStats);
	}
	
	/**
	 * 删除数据
	 * @param clickStats
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(ClickStats clickStats) {
		super.delete(clickStats);
	}
	
	/**
	 * 查询访问量统计数据
	 * @param natatoriumInfoId  游泳馆信息id
	 * @param yearMonthStr	年月
	 * @return List<CommonEcharts>
	 */
	public List<CommonEcharts> findClickStatsCountData(ClickStats clickStats){
		List<CommonEcharts> commonEchartsVOList = new ArrayList<CommonEcharts>();
		String dateStr = clickStats.getYearMonthStr();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		String[] yearMonth = dateStr.split("-");
		//获取月份的天数
		Integer dayNum = 0;
		try {
			dayNum = DateUtil.getDaysOfMonth(sdf.parse(dateStr));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		String yearStr = yearMonth[0];
		String monthStr = yearMonth[1];
		String dayStr;
		for (int i = 1; i <= dayNum; i++) {
			CommonEcharts commonEchartsVO = new CommonEcharts();
			commonEchartsVO.setName(i + "日");
			dayStr = i < 10 ? "0" + i : i + "";
//				commonEchartsVO.setValue("" + dao.countData(clickStats.getNatatoriumInfoId(), clickStats.getYear(), monthStr));
			commonEchartsVO.setValue("" + dao.countDayData(clickStats.getNatatoriumInfoId(), yearStr, monthStr, dayStr));
			commonEchartsVOList.add(commonEchartsVO);
		}
		return commonEchartsVOList;
	}
	
//	/**
//	 * 查询访问量统计数据
//	 * @param natatoriumInfoId  游泳馆信息id
//	 * @param yearMonthStr	年月
//	 * @return List<CommonEcharts>
//	 */
//	public List<CommonEcharts> findClickStatsCountData(ClickStats clickStats){
//		List<CommonEcharts> commonEchartsVOList = new ArrayList<CommonEcharts>();
//		Integer[] months = {1,2,3,4,5,6,7,8,9,10,11,12};
//		String monthStr;
//		for (Integer month : months) {
//			CommonEcharts commonEchartsVO = new CommonEcharts();
//			commonEchartsVO.setName(month + "月");
//			monthStr = month < 10 ? "0" + month : month.toString();
////			commonEchartsVO.setValue("" + dao.countData(clickStats.getNatatoriumInfoId(), clickStats.getYear(), monthStr));
//			commonEchartsVO.setValue("" + dao.countData(clickStats.getNatatoriumInfoId(), clickStats.getYear(), monthStr));
//			commonEchartsVOList.add(commonEchartsVO);
//		}
//		return commonEchartsVOList;
//	}
}